import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {
    public List<Integer> findAnagrams(String str, String p) {

        int len1 = str.length();
        int len2 = p.length();

        char[] ch = p.toCharArray();
        Arrays.sort(ch);

        List<Integer> ret = new ArrayList<>();

        int cur = 0;
        while (cur < len1 - len2 + 1) {
            String temp = str.substring(cur, cur + len2);

            char[] ch1 = temp.toCharArray();
            Arrays.sort(ch1);

            if ((new String(ch)).equals(new String(ch1))) {
                ret.add(cur);
            }
            cur++;
        }

        return ret;
    }
}